package com.example.tellwin;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.example.tellwin.base.CpBaseActivty;
import com.example.tellwin.base.DaggerRxComponent;
import com.example.tellwin.mine.bean.UserBean;
import com.example.tellwin.mine.contract.IdentitySelectContract;
import com.example.tellwin.mine.presenter.IdentitySelectPresenter;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class IdentitySelectActivity extends CpBaseActivty implements IdentitySelectContract.View {

    @BindView(R.id.student_ll)
    LinearLayout studentLl;
    @BindView(R.id.teacher_ll)
    LinearLayout teacherLl;

    @Inject
    IdentitySelectPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_identity_select);
        ButterKnife.bind(this);
        initViews();
        initEvents();
        initDatas();
    }

    @Override
    protected void initViews() {
        DaggerRxComponent.builder()
                .baseAppComponent(MainApplication.getAppComponent())
                .build()
                .inject(this);
        mPresenter.attachView(this);
    }

    @Override
    protected void initEvents() {

    }

    @Override
    protected void initDatas() {
        setTitle(R.string.identity_select);
    }

    @OnClick({R.id.student_ll, R.id.teacher_ll})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.student_ll:
                mPresenter.selectIdentity("1");
                break;
            case R.id.teacher_ll:
                mPresenter.selectIdentity("2");
                break;
        }
    }

    @Override
    public void selectIdentitySuccess() {
        UserBean userBean = AppHelper.getInstance().getUser();
        userBean.setIsIdentity(1);
        AppHelper.getInstance().saveUser(userBean,this);
        Intent intent = new Intent(IdentitySelectActivity.this,MainActivity.class);
        startActivity(intent);
        finish();
    }
}
